<template>
  <view class="container">
    <!-- 咨询师头像 -->
    <image class="avatar" :src="consultant.psy_pic" mode="aspectFill"></image>
    
    <!-- 咨询师信息 -->
    <view class="info">
      <text class="name">{{ consultant.psy_name }}</text>
      <view class="divider"></view>
      <text class="id">ID: {{ consultant.psy_id }}</text>
    </view>
    
    <!-- 个人简介方框 -->
    <view class="intro-box">
      <text class="intro-title">个人简介</text>
      <view class="divider"></view>
      <text class="intro-content">{{ consultant.introduction || '暂无简介' }}</text>
    </view>

    <!-- 按钮 -->
    <view class="buttons">
      <button class="btn-book" @click="bookOnline(consultant)">线上预约</button>
      <button class="btn-book" @click="bookOffline(consultant)">线下预约</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      consultant: {
        psy_pic: '',
        psy_name: '',
        psy_id: 1,
        introduction: '',
      }
    };
  },
  onLoad(options) {
    // 从路由参数中获取咨询师ID
    const consultantId = options.id;
    this.fetchConsultantInfo(consultantId);
  },
  methods: {
    // 获取咨询师详细信息
    fetchConsultantInfo(id) {
      uni.request({
        url: `http://127.0.0.1:5001/api_1_0/psyConsultant/${id}`, // 修正URL
        method: 'GET',
        success: (res) => {
          if (res.data.code === '2000') {
            this.consultant = res.data.data[0];
          } else {
            uni.showToast({ title: '获取咨询师信息失败', icon: 'none' });
          }
        },
        fail: (err) => {
          uni.showToast({ title: '网络错误', icon: 'none' });
        }
      });
    },
   // 线上预约
    bookOnline(consultant) {
      uni.navigateTo({
        url: `/pages/user/consult/order_online?id=${consultant.psy_id}`
      });
    },
    // 线下预约
    bookOffline(consultant) {
      uni.navigateTo({
        url: `/pages/user/consult/order_offline?id=${consultant.psy_id}`
      });
    }
  }
};
</script>

<style scoped>
.container {
  padding: 20px;
  display: flex;
  flex-direction: column;
  height: 85vh;
}

.avatar {
  width: 100%;
  height: 90%; 
  object-fit: cover; /* 确保图片按比例缩放并填充容器 */
  margin-bottom: 20px;
}

.info {
  margin-bottom: 20px;
}

.name {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 10px;
}

.id {
  font-size: 18px;
  color: #333;
  margin-bottom: 10px;
}

.tags {
  font-size: 18px;
  color: #81B337;
}

.intro-box {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-top: 20px;
}

.intro-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 10px;
}

.divider {
  height: 1px;
  background-color: #ddd;
  margin-bottom: 10px;
}

.intro-content {
  font-size: 16px;
  color: #333;
}

.footer {
  flex-shrink: 0; /* 防止内容过多时footer被挤压 */
  padding: 10px;
  background-color: #fff; 
}

/* 按钮容器样式 */
.buttons {
  display: flex;
  gap: 10px;
}

/* 按钮样式 */
.btn-details,
.btn-book {
  flex: 1;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 14px;
  text-align: center;
  cursor: pointer;
}

.btn-details {
  background-color: #f0f0f0;
  color: #333;
}

.btn-book {
  background-color: #81b337;
  color: #fff;
}
</style>